package com.zzzzzz.account.dao;

import org.springframework.stereotype.Repository;

import com.google.code.morphia.query.Query;
import com.zzzzzz.account.model.Ticket;
import com.zzzzzz.core.dao.morphia.BaseDao;

@Repository
public class TicketDao extends BaseDao {
	
	public void add(Ticket ticket) {
		datastore.save(ticket);
	}

	public Ticket findByKey(String key) {
		return datastore.find(Ticket.class, "key", key).get();
	}

	public Ticket findByKeyAndType(String key, String type) {
		Query<Ticket> query = datastore.createQuery(Ticket.class);
		query.field("key").equal(key);
		query.field("type").equal(type);
		return query.get();
	}

	public void delByKey(String key) {
		Query<Ticket> query = datastore.createQuery(Ticket.class);
		query.field("key").equal(key);
		datastore.delete(query);
	}

}
